package com.wngbms.websocket.zookeeper;

/*
@Slf4j
@Component
public class UserNodeObserver implements ZkConst {

    @Autowired
    ZookeeperSupport zookeeperSupport;
    @Autowired
    ExecutorService zookeeperThreadPool;
    @Autowired
    UserHook userHook;

    private static final Map<String, CuratorCache> userCacheMap = new ConcurrentHashMap<>();

    public void registerUser(String userId) {
        log.info("register user:{}", userId);
        String absoluteUserPath = TRIM_NODE_ROOT_PATH + userId;

        String loginValue = getLoginValue(userId);
        zookeeperSupport.createEphemeral(absoluteUserPath, loginValue);
        log.info("user node {} has been created. value:{}", absoluteUserPath, loginValue);

        CuratorCacheListener curatorCacheListener = CuratorCacheListener
                .builder()
                .forChanges((oldNode, node) -> {
                    log.info("user event happen: oldNodeData:{} {}", getPath(oldNode), getContent(oldNode));
                    log.info("user event happen: newNodeData:{} {}", getPath(node), getContent(node));
                    String pathUserId = getPathUserId(node);
                    if (EventType.EVENT_NOTICE.equals(checkEventType(node))) {
                        userHook.userEventHook(pathUserId);
                    } else if (EventType.LOGIN.equals(checkEventType(node))) {
                        userHook.closeUserSession(pathUserId);
                    }
                }).build();

        CuratorCache curatorCache = CuratorCache
                .builder(zookeeperSupport.getClient(), absoluteUserPath).build();
        curatorCache.listenable().addListener(curatorCacheListener, zookeeperThreadPool);
        curatorCache.start();

        userCacheMap.put(userId, curatorCache);
    }

    public void unregisterUser(String userId) {
        log.info("unregister user:{}", userId);
        String absoluteUserPath = TRIM_NODE_ROOT_PATH + userId;

        CuratorCache curatorCache = userCacheMap.get(userId);
        if (curatorCache != null) {
            curatorCache.close();
            userCacheMap.remove(userId);
        }

        if (!zookeeperSupport.checkExists(absoluteUserPath)) {
            log.info("user node {} not exists.", absoluteUserPath);
            return;
        }

        zookeeperSupport.deletePath(absoluteUserPath);
    }

}
*/
